<?php
//ini_set("display_errors", "On");
//
//error_reporting(E_ALL | E_STRICT);
require_once "../php/funcs.php";

if (!session_id()) {
    session_start();
}
//存一次
//unset($_SESSION);
$conn = connect_to_db();
$activityTag = "Huggies_920_pome_h5_20180920";
$accountId = "gh_e4ad6bc7492f";
$company_key = "huggies_autumn";
$isWeixinBrowser = isWeixinBrowser();

if ($isWeixinBrowser == 1) {
	if (isset($_SESSION['wanmiOpenid'])
	    && !empty($_SESSION['wanmiOpenid'])
	    && $_SESSION['wanmiOpenid'] != 'unknown'
	) {
		$openid = $_SESSION['wanmiOpenid'];
	} else {
		//微信授权oauth2授权，获取code
		{
			$_SESSION['referer'] = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
			$redirectUrl = $CONFIG['UrlPrefix']
			               ."login.php";
			$redirectUrl = urlencode($redirectUrl);
			$baseUrl     = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="
			               .$CONFIG['appid']."&response_type=code&scope=snsapi_base";
			$finalUrl = $baseUrl
			            ."&redirect_uri=$redirectUrl&state=wanmi#wechat_redirect";
			header("Location:$finalUrl");

			exit();
		}
	}
} else {

	$openid = 'ozVCVuPJYfQQ3XaFpal_Rs36_50U'; //JYJ

//    echo "<h1>请从微信手机端访问，参与活动哦~</h1></script>";
//    exit();
}
?>
